using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Content;

using Programonica.Igramonica.Core;

namespace Programonica.Igramonica.Graphics.Settings
{
    public class GraphicsSettings : GameComponent
    {
        private Core.Settings m_settings;

        private GraphicsDeviceManager m_graphics;
        
        public GraphicsSettings(Game game, GraphicsDeviceManager graphics, Programonica.Igramonica.Core.Settings settings)
            : base(game)
        {
            m_settings = settings;

            m_graphics = graphics;
            
            graphics.PreparingDeviceSettings += new EventHandler<PreparingDeviceSettingsEventArgs>(graphics_PreparingDeviceSettings);
        }

        void graphics_PreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e)
        {
            e.GraphicsDeviceInformation.PresentationParameters.BackBufferHeight = m_settings.Height;

            e.GraphicsDeviceInformation.PresentationParameters.BackBufferWidth = m_settings.Width;

            e.GraphicsDeviceInformation.PresentationParameters.IsFullScreen = m_settings.IsFullScreen;

            if (m_settings.IsFullScreen)
            {
                if (m_settings.SynchronizeWithVerticalRetrace)
                {
                    e.GraphicsDeviceInformation.PresentationParameters.PresentationInterval = PresentInterval.Default;
                }
                else 
                {
                    e.GraphicsDeviceInformation.PresentationParameters.FullScreenRefreshRateInHz =
                        m_settings.RefreshRate;

                    e.GraphicsDeviceInformation.PresentationParameters.PresentationInterval = PresentInterval.Immediate;
                }
            }
        }

        public override void Initialize()
        {
            base.Initialize();
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }
    }
}